package com.xy.bizportdemo.database.entity;

import android.content.ContentValues;
import android.database.Cursor;

import com.example.messageutil.iface.ISmartMessageItem;

import java.util.HashMap;

/**
 * Created by admin on 2016/11/24.
 */

public class MessageItem implements ISmartMessageItem {
    public static final int MESSAGE_TYPE_INBOX = 1;
    public static final int MESSAGE_TYPE_OUTBOX = 4;
    public static final int MESSAGE_SOURCE_SYSTEM = 2;
    public static final int MESSAGE_SOURCE_USER = 1;

    private long msgId;
    private String body;
    private String address;
    private long date;
    private int boxId;
    private int source;

    public MessageItem() {
        this.date = System.currentTimeMillis();
        this.source = MESSAGE_SOURCE_USER;
    }

    public MessageItem setAddress(String address) {
        this.address = address;
        return this;
    }

    public long getMsgId() {
        return this.msgId;
    }

    public String getAddress() {
        return this.address;
    }

    public MessageItem setBody(String body) {
        this.body = body;
        return this;
    }

    public String getBody() {
        return this.body;
    }

    public MessageItem setDate(String date) {
        this.date = Long.parseLong(date);
        return this;
    }

    public long getDate() {
        return this.date;
    }

    public MessageItem setType(int type) {
        this.boxId = type;
        return this;
    }

    public int getType() {
        return this.boxId;
    }

    public MessageItem setSource(int source) {
        this.source = source;
        return this;
    }

    public int getSource() {
        return this.source;
    }

    public MessageItem(Cursor cursor) {
        this.msgId = Long.parseLong(cursor.getString(cursor.getColumnIndex(SmsDBTableMessage.KEY_ID)));
        this.address = cursor.getString(cursor.getColumnIndex(SmsDBTableMessage.KEY_ADDRESS));
        this.body = cursor.getString(cursor.getColumnIndex(SmsDBTableMessage.KEY_BODY));
        this.date = Long.parseLong(cursor.getString(cursor.getColumnIndex(SmsDBTableMessage.KEY_DATE)));
        this.source = cursor.getInt(cursor.getColumnIndex(SmsDBTableMessage.KEY_SOURCE));
        this.boxId = cursor.getInt(cursor.getColumnIndex(SmsDBTableMessage.KEY_TYPE));
    }

    public ContentValues getContentValues() {
        ContentValues values = new ContentValues();

        values.put(SmsDBTableMessage.KEY_ADDRESS, this.address);
        values.put(SmsDBTableMessage.KEY_BODY, this.body);
        values.put(SmsDBTableMessage.KEY_DATE, this.date);
        values.put(SmsDBTableMessage.KEY_SOURCE, this.source);
        values.put(SmsDBTableMessage.KEY_TYPE, this.boxId);

        return values;
    }

    @Override
    public String getSmsBody() {
        return getBody();
    }

    @Override
    public HashMap getSmartSmsExtendMap() {
        return null;
    }

    @Override
    public String getPhoneNum() {
        return getAddress();
    }

    @Override
    public String getServiceCenterNum() {
        return null;
    }

    @Override
    public long getSmsReceiveTime() {
        return getDate();
    }

    /**
     * return value: -1 is the default value
     * 0:卡1；1：卡2
     */
    @Override
    public int getSimIndex() {
        return -1;
    }

    @Override
    public String getICCID() {
        return null;
    }

    public int getBoxId() {
        return boxId;
    }
}
